<template>
  <div style="padding-top: 20px;padding-bottom: 20px;background-color:white;">
    <a-form :form="form">
      <a-form-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <a-input v-decorator="['projectName']" placeholder="请输入项目名称" ></a-input>
      </a-form-item>
      <a-form-item label="项目类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <a-input v-decorator="['projectType']" placeholder="请输入项目类型"></a-input>
      </a-form-item>
      <a-form-item label="项目简要说明" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <a-textarea v-decorator="['projectBrief']" rows="4" placeholder="请输入项目简要说明"/>
      </a-form-item>
      <a-form-item label="专家到场地点" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <a-input v-decorator="['professorWorkAddress']" placeholder="请输入专家到场地点"></a-input>
      </a-form-item>

      <a-form-item label="选择专家类型和对应人数" :labelCol="labelCol" :wrapperCol="wrapperCol" >
        <DynamicForm
          :data="childData"
          v-decorator="['projectOwnProfessorType']" ref="DynamicForm"></DynamicForm>
      </a-form-item>

      <a-form-item label="专家到场时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <j-date
          :showTime="true"
          dateFormat="YYYY-MM-DD HH:mm:ss"
          v-decorator="['professorWorkBeginTime']">
        </j-date>
      </a-form-item>
      <a-form-item label="项目附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <j-upload v-decorator="['projectFile']" :trigger-change="true"></j-upload>
      </a-form-item>
      <a-form-item
        :wrapper-col="{
        xs: { span: 14, offset: 0 },
        sm: { span: 16, offset: 4 },
      }"
      >
        <a-button block type="primary" @click="handleOk" style="text-align: center">
          提交
        </a-button>
      </a-form-item>


    </a-form>

  </div>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JUpload from '@/components/jeecg/JUpload'
  import JCategorySelect from '@/components/jeecg/JCategorySelect'
  import JDate from '@/components/jeecg/JDate'
  import DynamicForm from './modules/DynamicForm'
  import {getAction} from "../../api/manage";
  export default {
    name: "ProjectProfessorInfoAdd",
    components: {
      JUpload,
      JCategorySelect,
      JDate,
      DynamicForm,

    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/projectProfessorInfo/add",
          edit: "/projectProfessorInfo/edit",
          queryProfessorNumber:"/projectProfessorInfo/queryProfessorNumber"
        },
        childData:[],
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        console.log("走这应该是")
        console.log(record)
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'projectName','projectType','projectBrief','projectFile','professorWorkBeginTime','professorWorkAddress'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        let childData = this.$refs.DynamicForm.data;
        this.form.setFieldsValue({
          projectOwnProfessorType: childData
        })
        console.log("childData")
        console.log(childData)
        const that = this;
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
              method = 'put';
            }
            let formData = Object.assign(this.model, values);
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'projectName','projectType','projectBrief','projectFile','professorWorkBeginTime','professorWorkAddress'))
      },


    }
  }
</script>